<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

include_once("../modelo/ModeloVehiculo.php");
include_once("../control/ControlVehiculo.php");


$cVehiculo = new ControlVehiculo();

$cVehiculo->getListaVehiculos();

$arVehiculos = $_SESSION['arAutomoviles'];
?>
<script type="text/javascript"  lang="javascript" >
    //$(document).ready(function(){
    //   $("#new").click(function() {
    //       $("#title h1").html("Crear Aoutomovil");
    //     $("#automoviles").load("VistaAutomoviles_datos.php");
    // });
    // });
    $(document).ready( function () {
        var oTable = $('#tablaAutomoviles').dataTable( {
            "sDom": 'R<"H"lfr>t<"F"ip>',
            "bJQueryUI": true,
            "sPaginationType": "full_numbers",
            "bPaginate": true,
            "bLengthChange": true,
            "bFilter": true,
            "bSort": false,
            "bInfo": true,
            "bAutoWidth": true
        } );
    } );
    
    function eliminar(id){
        if(confirm('Seguro desea eliminar el registro?')){
            $.post("../control/ControlVehiculo.php",{opcion:'eliminar',vehicodsx:id},
            function(data){
                var row = data.split("*|*");
                var datalocal=row[0];
                if(datalocal =='ok'){
                    $("#mensaje").html(row[1]); 
                    $("#automoviles").load("VistaVehiculos.php");
                }else if(datalocal=='false'){
                    alert(row[1]);
                }
            },
            null); 
        }
    }
</script>
<div id="automoviles">
    <div id="title"><h1>Vehiculos</h1></div>
    <div id="newAutomoviles">
        <a id="new" href="Vehiculos.php?op=crear"><img src="../css/images/add.png" alt="Crear un nuevo Vehiculo"/>Nuevo Vehiculo</a>
    </div>
    <div id="divtablaAutomoviles">
        <table id="tablaAutomoviles" class="tabla_datos">
            <thead>
                <tr>
                    <th scope="col">Id</th>
                    <th scope="col">Tipo Vehiculo</th>
                    <th scope="col">Placa</th>
                    <th scope="col">Marca</th>
                    <th scope="col">Modelo</th>
                    <th scope="col">Sucursal</th>
                    <th scope="col">Disponible</th>
                    <th scope="col">Opci&oacute;n</th>
                </tr>
            </thead>
            <tbody>

                <?php
                foreach ($arVehiculos as $oVehiculo) {
                    $estadoDisponible = "";
                    if ($oVehiculo-> vehidisponible == '0') {
                        $estadoDisponible = 'NO';
                    } else {
                        $estadoDisponible = 'SI';
                    }
                    ?>
                    <tr>
                        <td><?php echo $oVehiculo->vehicodsx ?></td>
                        <td><?php echo $oVehiculo->tipovehinombre ?></td>
                        <td><?php echo $oVehiculo->vehiplaca ?></td>
                        <td><?php echo $oVehiculo->vehimodelo ?></td>
                        <td><?php echo $oVehiculo->vehimarca ?></td>
                        <td><?php echo $oVehiculo->sucurnombre ?></td>
                        <td><?php echo $estadoDisponible ?></td>
                        <td id="tdopcion"> 
                            <a href="Vehiculos.php?op=actualizar&id=<?php echo $oVehiculo->vehicodsx ?>">
                                <img src="../css/images/modificar.gif" border="0" alt="Modificar" title="Modificar" > 
                            </a> |
                            <a href="#">
                                <img src="../css/images/eliminar.png" border="0" alt="Eliminar" title="Eliminar" 
                                     onclick="eliminar('<?php echo $oVehiculo->vehicodsx ?>')">
                            </a>
                        </td>
                    </tr>
                    <?php
                }
                ?> 
            </tbody>

        </table>
    </div>
</div>